"""
网页版应用入口文件
"""
import os
import sys
import subprocess
from pathlib import Path

def main():
    """
    启动 Streamlit 网页应用
    """
    project_root = Path(__file__).parent.resolve()
    script_path = project_root / "src" / "web" / "web_app.py"
    
    # 创建一个新的环境变量字典，并将项目根目录添加到 PYTHONPATH
    env = os.environ.copy()
    python_path = env.get("PYTHONPATH", "")
    env["PYTHONPATH"] = f"{project_root}{os.pathsep}{python_path}"
    
    command = [sys.executable, "-m", "streamlit", "run", str(script_path)]
    
    print(f"执行命令: {' '.join(command)}")
    print(f"PYTHONPATH: {env['PYTHONPATH']}")
    
    # 使用 subprocess.run 启动，并传入修改后的环境变量
    subprocess.run(command, env=env)

if __name__ == "__main__":
    main()